//
// Created by steven on 2017/2/24.
// Copyright (c) 2017 steven. All rights reserved.
//

#import "GMGuardTableViewCell.h"

@implementation GMGuardTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupMainView];
    }

    return self;
}

#pragma mark - set up main view
- (void)setupMainView {
    [self addSubview:self.guardImageView];
    [self addSubview:self.guardNoLabel];
    [self addSubview:self.dateLabel];
    [self addSubview:self.usageLabel];
    
    // guard image view
    [self.guardImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.guardImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:38];
    [self.guardImageView autoSetDimensionsToSize:CGSizeMake(32, 52)];
    
    // date label
    [self.dateLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self withOffset:-12];
    [self.dateLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.guardImageView withOffset:40];
    
    // guard no label
    [self.guardNoLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self withOffset:12];
    [self.guardNoLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.guardImageView withOffset:40];
    
    // usage label
    [self.usageLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.dateLabel withOffset:18];
    [self.usageLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.dateLabel];
}

#pragma mark - guardImageView
- (UIImageView *)guardImageView {
    if (!_guardImageView) {
        _guardImageView = [[UIImageView alloc] init];
        _guardImageView.image = [UIImage imageNamed:@"guard-icon"];
    }

    return _guardImageView;
}

#pragma mark - guardNoLabel
- (UILabel *)guardNoLabel {
    if (!_guardNoLabel) {
        _guardNoLabel = [[UILabel alloc] init];
        _guardNoLabel.font = [UIFont systemFontOfSize:10];
        _guardNoLabel.textColor = HINT_COLOR;
    }

    return _guardNoLabel;
}

#pragma mark - date label
- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.font = [UIFont systemFontOfSize:10];
        _dateLabel.textColor = HINT_COLOR;
    }

    return _dateLabel;
}

#pragma mark - usage label
- (UILabel *)usageLabel {
    if (!_usageLabel) {
        _usageLabel = [[UILabel alloc] init];
        _usageLabel.font = [UIFont systemFontOfSize:10];
        _usageLabel.textColor = HINT_COLOR;
    }
    
    return _usageLabel;
}

@end
